package com.hulk.dryad.manage.boot.upload2;

import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 文件上传配置
 *
 * @author hulk
 */
@RequiredArgsConstructor
@Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@EnableConfigurationProperties(DryadUploadProperties.class)
public class DryadServletUploadConfiguration implements WebMvcConfigurer {

	private final DryadUploadProperties properties;

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		String path = properties.getSavePath();
		registry.addResourceHandler(properties.getUploadPathPattern())
			.addResourceLocations("file:" + path + "/");
	}

}
